package dome.common;

public class AQIUtils {
    private static final String[] AQI_DESCRIPTIONS = {"优", "良", "轻度污染", "中度污染", "重度污染", "严重污染"};
    private static final int[] so2Levels = {50, 150, 475, 800, 1600};
    private static final int[] coLevels = {5, 10, 35, 60, 90};
    private static final int[] pm25Levels = {35, 75, 115, 150, 250};

    public static String getAQILevelAndDescription(double so2, double co, double pm25) {
        int so2AQILevel = getAQILevelForPollutant(so2, so2Levels);
        int coAQILevel = getAQILevelForPollutant(co, coLevels);
        int pm25AQILevel = getAQILevelForPollutant(pm25, pm25Levels);
        int maxLevel = Math.max(Math.max(so2AQILevel, coAQILevel), pm25AQILevel);
        return   maxLevel + " " + AQI_DESCRIPTIONS[maxLevel - 1];
    }

    private static int getAQILevelForPollutant(double value, int[] levels) {
        for (int i = 0; i < levels.length; i++) {
            if (value <= levels[i]) {
                return i + 1;
            }
        }
        return levels.length + 1;
    }
}
